//
//  FYCommentView.m
//  ThePainter
//
//  Created by Sean on 15/8/21.
//  Copyright (c) 2015年 FeiYu. All rights reserved.
//

#import "FYCommentView.h"

@interface FYCommentView ()

@property (nonatomic)FYComment *fyComment;

- (void)initView;

@end

@implementation FYCommentView

- (id)initWithComment:(FYComment*)comment {
    if (self = [super init]) {
        self.fyComment = comment;
        [self initView];
    }
    return self;
}

- (void)initView {
    
    self.backgroundColor = [UIColor whiteColor];
    
    //头像
    CGFloat aW = 30;
    CGFloat dis = 10;
    UIImageView *imgAvatar = [[UIImageView alloc] init];
    imgAvatar.backgroundColor = [UIColor clearColor];
    imgAvatar.layer.cornerRadius = aW / 2;
    imgAvatar.layer.masksToBounds = YES;
    [imgAvatar sd_setImageWithURL:[NSURL URLWithString:self.fyComment.user.avatar] placeholderImage:[UIImage imageNamed:@"icon_set_avatar"]];
    [self addSubview:imgAvatar];
    [imgAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@(aW));
        make.width.mas_equalTo(@(aW));
        make.top.equalTo(self.mas_top).offset(dis);
        make.left.equalTo(self.mas_left).offset(dis);
    }];
    
    //昵称
    FYLabel *labName = [[FYLabel alloc] initWithString:self.fyComment.user.username size:fyLabSize3 color:fyColorLightGary];
    [self addSubview:labName];
    [labName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgAvatar.mas_right).offset(dis);
        make.top.equalTo(self.mas_top).offset(dis);
    }];
    
    //评论
    CGFloat comW = [FYUtils fyScreenWidth] - aW;
    FYDesc *descComment = [[FYDesc alloc] initWithString:self.fyComment.comment fontSize:fyLabSize3 color:[UIColor blackColor] width:comW];
    [self addSubview:descComment];
    [descComment mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgAvatar.mas_right).offset(dis);
        make.right.equalTo(self.mas_right).offset(-dis);
        make.top.equalTo(labName.mas_bottom);
    }];
    
    //横线
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = fyColorLightGary;
    [self addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@(0.5));
        make.left.equalTo(self.mas_left).with.offset(dis);
        make.right.equalTo(self.mas_right).with.offset(-dis);
        make.top.equalTo(descComment.mas_bottom).with.offset(dis);
    }];

    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(line1.mas_bottom);
    }];
}

@end
